import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const state = {
  // 2.因为sessionStorage存储的rightList在第一步存储时转换为字符串了，这一步需要还原回数组
  rightList: JSON.parse(sessionStorage.getItem('rightList') || '[]'),
  username: sessionStorage.getItem('username'),
  user_pic: sessionStorage.getItem('user_pic')
}
const mutations = {
  setRightList(state, data) {
    state.rightList = data
    // 1.因为data是数组，所以需要转换为字符串
    sessionStorage.setItem('rightList', JSON.stringify(data))
  },
  setUsername(state, data) {
    state.username = data
    sessionStorage.setItem('username', data)
  },
  setUserPic(state, data) {
    state.user_pic = data
    sessionStorage.setItem('user_pic',data)
  }
}
const getters = {}
const actions = {}

export default new Vuex.Store({
  state,
  mutations,
  getters,
  actions
})
